﻿package game 
{

	import fl.controls.TextInput;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import game.events.EventData;
	import game.exchangeddata.HashTable;
	import game.exchangeddata.UserInfo;
	import common.Utility;
	/**
	 * ...
	 * @author ... Doan Nguyen Thuy Nha Truc (Bamboo)	
	 */
	public class AccountInfoPanel extends MovieClip
	{
		public var txtAccInfoTf:TextField;
		public var txtAccNameTf:TextField;
		public var txtAccNameValueTf:TextField;
		
		public var txtAccBalanceTf:TextField;
		public var txtAccBalanceValueTf:TextField;
		public var txtCurrentPassTf:TextField;
		public var txtNewPassTf:TextField;
		public var txtConfirmNewPassTf:TextField;
		
		public var txtCommRateTf:TextField;
		public var txtCommRateValueTf:TextField;
		public var txtUpperLimitTf:TextField;
		public var txtUpperLimitValueTf:TextField;
		public var txtLowerLimitTf:TextField;
		public var txtLowerLimitValueTf:TextField;
		public var txtOldPassTi:TextInput;
		public var txtNewPassTi:TextInput;
		public var txtConfirmPassTi:TextInput;
		public var txtOkTf:TextField;
		public var txtCancelTf:TextField;
		public var btnAcceptNewPass:SimpleButton;
		public var btnCancelChangePass:SimpleButton;
		public var accountInfo:UserInfo;
		public function AccountInfoPanel() 
		{
			accountInfo= new UserInfo();
			hide();
			this.btnCancelChangePass.useHandCursor = true;
			this.btnAcceptNewPass.useHandCursor = true;
			this.txtOkTf.mouseEnabled = false;
			this.txtCancelTf.mouseEnabled = false;
			this.btnCancelChangePass.addEventListener(MouseEvent.CLICK, clickCancelChangePassHdl);
			this.btnAcceptNewPass.addEventListener(MouseEvent.CLICK, clickAcceptNewPassHdl);
		}
		
		private function clickAcceptNewPassHdl(e:MouseEvent):void 
		{
			var event:EventData = new EventData(EventData.SHOW_MS, true);
			var valueMs:String; 
			if (this.txtOldPassTi.text == "") {
				valueMs = GlobalVariables.langInfo.hashTable.lookupString("RequireOldPassword");
				event.ms = valueMs;
				dispatchEvent(event);
			}else {
				if (this.txtNewPassTi.text == this.txtConfirmPassTi.text )
				{
					if (this.txtNewPassTi.text == "") {
						valueMs = GlobalVariables.langInfo.hashTable.lookupString("RequireNewPassword");
						event.ms = valueMs;
						dispatchEvent(event);
					}else {
						event = new EventData(EventData.CHANGE_PASS, true);
						accountInfo.oldPass = this.txtOldPassTi.text;
						accountInfo.newPass = this.txtNewPassTi.text;
						dispatchEvent(event);
					}
					
				}else {
					valueMs = GlobalVariables.langInfo.hashTable.lookupString("ReEnterPasswordNotMatch");
					event.ms = valueMs;
					dispatchEvent(event);
				}
			}
			hide();	
		}
		
		private function clickCancelChangePassHdl(e:MouseEvent):void 
		{
			hide();
			this.txtOldPassTi.text = "";
			this.txtNewPassTi.text = "";
			this.txtConfirmPassTi.text = "";
		}
		public function show():void {
			this.visible = true;
			
		}
		public function hide():void {
			this.visible = false;
		}
		public function initText(hashTableInfo:HashTable):void {
				this.txtAccInfoTf.text = hashTableInfo.lookupString("accountMSG");
				this.txtAccNameTf.text = hashTableInfo.lookupString("anameMSG");
				this.txtAccBalanceTf.text = hashTableInfo.lookupString("balanceMSG");
				this.txtUpperLimitTf.text = hashTableInfo.lookupString("ulimitMSG");
				this.txtLowerLimitTf.text = hashTableInfo.lookupString("llimitMSG");
				this.txtCommRateTf.text = hashTableInfo.lookupString("cRateMsg");
				this.txtCurrentPassTf.text = hashTableInfo.lookupString("cpassMSG");
				this.txtNewPassTf.text = hashTableInfo.lookupString("npassMSG");
				this.txtConfirmNewPassTf.text = hashTableInfo.lookupString("ccpassMSG");
				this.txtOkTf.text = hashTableInfo.lookupString("btnOK");
				this.txtCancelTf.text = hashTableInfo.lookupString("btnCancel");
				this.txtOldPassTi.text = "";
				this.txtNewPassTi.text = "";
				this.txtConfirmPassTi.text = "";
				
		}
		
		public function updateValueAccountInfo(info:Object):void {
			var accountInfo:UserInfo = UserInfo(info);
			this.accountInfo = UserInfo(info);
			trace("accountInfo.balance:" + accountInfo.balance + ":accountInfo.commissionRate :" + accountInfo.commissionRate + ":accountInfo.maxBet:" + accountInfo.maxBet +":accountInfo.minBet:" + accountInfo.minBet);
			
			this.txtAccNameValueTf.text = accountInfo.userName;
			this.txtAccBalanceValueTf.text = Utility.currency(accountInfo.balance, 2 , "");
			this.txtCommRateValueTf.text = Utility.currency(accountInfo.commissionRate, 2, "");
			this.txtUpperLimitValueTf.text = Utility.currency(accountInfo.maxBet);
			this.txtLowerLimitValueTf.text = Utility.currency(accountInfo.minBet);
		}
	}

}